using System;
using System.Windows.Controls;

namespace FluentSilverlight.Expressions.Buttons
{
    public class ButtonExpression<TModel> : ButtonBaseExpression<ButtonExpression<TModel>, TModel, Button>
        where TModel : class
    {
        private object content;

        public ButtonExpression(TModel model, string content)
            : this(model, string.Format("Button_{0}", Guid.NewGuid()), content)
        {}

        public ButtonExpression(TModel model, string name, string content)
            : base(model, name)
        {
            this.content = content;
        }

        public ButtonExpression<TModel> Content(object value)
        {
            content = value;
            return thisInstance();
        }

        public static implicit operator Button(ButtonExpression<TModel> expression)
        {
            var button = new Button();
            expression.BuildUp(button);
            return button;
        }

        protected override void BuildUp(Button element)
        {
            base.BuildUp(element);

            element.Content = content;
        }

        protected override ButtonExpression<TModel> thisInstance()
        {
            return this;
        }

        protected override object GetCommandParameter(Button item)
        {
            return false;
        }
    }
}